package com.mitdy.sg.common.bean;

/**
 * 
 * JSON模型
 * 
 * 用户后台向前台返回的JSON对象
 *
 * 
 */
public class JsonResult implements java.io.Serializable {

	private static final long serialVersionUID = -4652918180001959792L;
	
	private boolean success = true;

	private String message = "";

	private int code = 1;

	private Object result = null;

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
		if (!success){
			this.code = -1;
		}
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object obj) {
		this.result = obj;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public JsonResult(){
		this.result = null;
		//成功默认为1
		this.code = 1;
		this.message = "成功";
	}

	public JsonResult(boolean success) {
		this.success = success;
	}

	public JsonResult(Object result){
		this.result = result;
		//成功默认为1
		this.code = 1;
		this.message = "成功";
	}

	public JsonResult(Object result, int code, String message){
		this.result = result;
		this.code = code;
		this.message = message;
		if(this.code != 1){
			this.setSuccess(false);
		}
	}

	public static JsonResult successInstance(){
		return new JsonResult(null,1,"成功");
	}

	public static JsonResult failInstance(String message){
		return new JsonResult(null,-1,message);
	}

}
